package com.zwan.oam_rtc.utils.messages;

import com.zwan.oam_rtc.utils.wintcp.ByteTransfer;

import java.nio.ByteBuffer;


public class NewAccessMsgHead extends AbstractStruct
{
	/**
	 * 消息长度
	 */
    public static final int LENGTH = 31;
    /**
     * 触发业务的事件号
     */
	public static final int SEND_EVENTID = 30000;

	/**
	 * 网络类型
	 */
	public static final int NETTYPE_CDMA = 0;
	public static final int NETTYPE_GSM = 1;
	public static final int NETTYPE_PSTN = 2;
	public static final int NETTYPE_PARLAY = 5;

	/**
	 * 试呼模式: 启动试呼 0x01
	 */
	public static final byte INITCALLMODE_CALL = 0x01;

	/**
	 * 试呼模式 ：定时留言通知 0x02
	 */
	public static final byte INITCALLMODE_MSG = 0x02;

	/**
	 * 试呼模式 ：不呼出 0x03
	 */
	public static final byte INITCALLMODE_NONE = 0x03;

	/**
	 * 消息目的地  1: To SSP
	 */
	public static final byte DEST_TOSSP = 0x01;
	/**
	 * 消息目的地  8: To IP 智能外设
	 */
	public static final byte DEST_TOIP = 0x08;

    private int index = 0;	// 申请的对话号,请求时不填
    private short Password = 1111;	// 消息密码 1111
    private byte Type;		   // 除短消息接口外，其他接口没有特殊要求都不填
    private int Skey = 131261; // 缺省触发77业务
    private short CidIndex;
    private byte[] IdetifyCode = { 'z', 'w', 'a', 'n', 0, 0, 0, 0, 0, 0 };
    private byte InitCallMode = 3;  // 试呼模式 1:启动试呼,2:定时留言通知,3:不向SIU申请对话号,直接触发业务 无特殊要求可填3
    private int SourceKey = 0; 			// 消息源
    private byte Destination = DEST_TOSSP;	// 消息目的地 1:To ssp,8:To IP,无特殊要求填1
    private byte MsgType = 0;		// 消息类型,无特殊要求不填
    private byte NoticeMode = 0;	// 通知模式,无特殊要求不填

    public NewAccessMsgHead() {
    	super();
//    	CidIndex = SDSMsgHead.getNextDlgId();
    }

	public void writeToBuffer(ByteBuffer bf) {
		//bf.order(ByteOrder.LITTLE_ENDIAN);
        bf.putInt(index);
        bf.putShort(Password);
        bf.put(Type);
        bf.putInt(Skey);
        bf.putShort(CidIndex);
        bf.put(IdetifyCode);
        bf.put(InitCallMode);
        bf.putInt(SourceKey);
        bf.put(Destination);
        bf.put(MsgType);
        bf.put(NoticeMode);
    }
    
    public void readFromBuffer(ByteBuffer bf){
    	//bf.order(ByteOrder.LITTLE_ENDIAN);
    	this.index = bf.getInt();
        this.Password = bf.getShort();
        this.Type = bf.get();
        this.Skey = bf.getInt();
        this.CidIndex = bf.getShort();
        bf.get(this.IdetifyCode);
        this.InitCallMode = bf.get();
        this.SourceKey = bf.getInt();
        this.Destination = bf.get();
        this.MsgType = bf.get();
        this.NoticeMode = bf.get();
    }

    public int getLength() {
        return LENGTH;
    }

    public short getCidIndex() {
        return CidIndex;
    }

    public void setCidIndex(short cidIndex) {
        this.CidIndex = cidIndex;
    }

    public byte getDestination() {
        return Destination;
    }

    public void setDestination(byte destination) {
        this.Destination = destination;
    }

    public String getIdetifyCode() {
        return ByteTransfer.getString(IdetifyCode);
    }

    public void setIdetifyCode(String idetifyCode) {
        if (idetifyCode != null) {
            this.IdetifyCode = ByteTransfer.trans(idetifyCode,
                    IdetifyCode.length);
        }
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public byte getInitCallMode() {
        return InitCallMode;
    }

    public void setInitCallMode(byte initCallMode) {
        this.InitCallMode = initCallMode;
    }

    public byte getMsgType() {
        return MsgType;
    }

    public void setMsgType(byte msgType) {
        this.MsgType = msgType;
    }

    public byte getNoticeMode() {
        return NoticeMode;
    }

    public void setNoticeMode(byte noticeMode) {
        this.NoticeMode = noticeMode;
    }

    public short getPassword() {
        return Password;
    }

    public void setPassword(short password) {
        this.Password = password;
    }

    public int getSkey() {
        return Skey;
    }

    public void setSkey(int skey) {
        this.Skey = skey;
    }
    
//    public static final 
    // nettype 
    /**
     *
     * @param netType
     * @param skey
     */
    
    public void setServiceKey(int netType, int skey){
//    	if (netType >= 0 && netType < )
    	this.Skey = netType * 65536 + skey;
    }
    
    public int getServiceKey(){
    	return this.Skey % 65536;
    }

    public int getSourceKey() {
        return SourceKey;
    }

    public void setSourceKey(int sourceKey) {
        this.SourceKey = sourceKey;
    }

    public byte getType() {
        return Type;
    }

    public void setType(byte type) {
        this.Type = type;
    }
    
}
